#include <vector>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>

struct vert
{
    double a[3];
};

int main(int argc, char *argv[])
{
    std::vector<vert> vertice;
    FILE *fp_1;
    fp_1 = fopen(argv[1], "r");
    
    while(!feof(fp_1)){
        vert v;
        fscanf(fp_1,"%lf %lf %lf\n",&v.a[0],&v.a[1],&v.a[2]);
        vertice.push_back(v);
    }

    fclose(fp_1);

    pcl::PointCloud<pcl::PointXYZ> cloud;

    // Fill in the cloud data
    cloud.width = static_cast<int>(vertice.size());
    cloud.height = 1;
    cloud.is_dense = false;
    cloud.points.resize(cloud.width * cloud.height);

    for (size_t i = 0; i < cloud.points.size(); ++i)
    {
        cloud.points[i].x = vertice[i].a[0];
        cloud.points[i].y = vertice[i].a[1];
        cloud.points[i].z = vertice[i].a[2];
    }
    pcl::io::savePCDFileASCII(argv[2], cloud);

    return 0;
}

int numofPoints(char *fname)
{
    int n = 0;
    int c = 0;
    FILE *fp;
    fp = fopen(fname, "r");
    do
    {
        c = fgetc(fp);
        if (c == '\n')
        {
            ++n;
        }
    } while (c != EOF);
    fclose(fp);
    return n;
}